package iso3.pt.action;



import iso3.pt.model.Alumno;
import iso3.pt.model.Asignatura;
import iso3.pt.model.Profesor;
import iso3.pt.service.PtDaoService;

import java.util.ArrayList;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

public class LecturerAction  extends ActionSupport implements Preparable{
	
	private ArrayList<Asignatura> asigs = new ArrayList<Asignatura>();
	private Profesor prof = null;
	private PtDaoService dao = null;
	private ArrayList<Alumno> listAlus;
	private String nomAsig;
	private int asigID;
	
	public String doLogout() throws Exception{
		Map s = ActionContext.getContext().getSession();
		s.remove("logged");		
		return "logout";		
	}
	
	public String doLecturer(){
		return SUCCESS;
	}

	@Override
	public void prepare() throws Exception {
		if (dao == null){
			dao = new PtDaoService();
		}
		asigs =  new ArrayList<Asignatura>();
		try {
			prof = (Profesor)ActionContext.getContext().getSession().get("logged");
			for (Asignatura asig : dao.getAsignaturasProfesor(prof.getDni())){
				asigs.add(asig);
			}	
		} catch (Exception e) {
			System.out.print(e.getMessage());
		}

	}
	
	public String doListStudents(){
		listAlus = new ArrayList<Alumno>();
		nomAsig = dao.getAsignatura(asigID).getNombre();
		
		try {
			if (prof != null){
				for(Alumno alu : dao.getAlumnos(asigID)){
					listAlus.add(alu);
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		return "listaEstudiantes";
		
	}
	
	public String addMark(){
		return "addMark";
	}

	public ArrayList<Asignatura> getAsigs() {
		return asigs;
	}

	public void setAsigs(ArrayList<Asignatura> asigs) {
		this.asigs = asigs;
	}

	public Profesor getProf() {
		return prof;
	}

	public void setProf(Profesor prof) {
		this.prof = prof;
	}

	public PtDaoService getDao() {
		return dao;
	}

	public void setDao(PtDaoService dao) {
		this.dao = dao;
	}

	public ArrayList<Alumno> getListAlus() {
		return listAlus;
	}

	public void setListAlus(ArrayList<Alumno> listAlus) {
		this.listAlus = listAlus;
	}

	public String getNomAsig() {
		return nomAsig;
	}

	public void setNomAsig(String nomAsig) {
		this.nomAsig = nomAsig;
	}

	public int getAsigID() {
		return asigID;
	}

	public void setAsigID(int asigID) {
		this.asigID = asigID;
	}
}
